package com.lanyou.esb.service;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.mail.internet.MimeMessage;
import javax.transaction.Transactional;

import org.apache.commons.httpclient.HttpException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.lang3.time.FastDateFormat;
import org.apache.velocity.app.VelocityEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.mail.javamail.MimeMessagePreparator;
import org.springframework.stereotype.Service;
import org.springframework.ui.velocity.VelocityEngineUtils;

import redis.clients.jedis.exceptions.JedisException;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.google.gson.JsonObject;
import com.lanyou.cook.common.Constants;
import com.lanyou.cook.datadictionary.UserLogOpt;
import com.lanyou.cook.entity.domain.FieldSystem;
import com.lanyou.cook.entity.domain.userManagement.MailSenderInfo;
import com.lanyou.cook.entity.domain.userManagement.User;
import com.lanyou.cook.paramsetting.Keys;
import com.lanyou.cook.paramsetting.ParamSettingService;
import com.lanyou.cook.paramsetting.vo.SmtpSetting;
import com.lanyou.cook.repository.userManagement.UserRepository;
import com.lanyou.cook.service.UserLogService;
import com.lanyou.cook.util.MailUtil;
import com.lanyou.cook.util.gson.GsonUtil;
import com.lanyou.esb.common.CommonUtils;
import com.lanyou.esb.datadictionary.AlarmLevel;
import com.lanyou.esb.datadictionary.IsolationStatus;
import com.lanyou.esb.entity.Http;
import com.lanyou.esb.entity.IfAlarm;
import com.lanyou.esb.entity.IfAlarmHis;
import com.lanyou.esb.entity.IfAlarmWorkOrder;
import com.lanyou.esb.entity.IfAlarmWorkOrderHis;
import com.lanyou.esb.exception.IfAlarmException;
import com.lanyou.esb.exception.ServiceHandlerException;
import com.lanyou.esb.redis.proxy.impl.HttpJedisProxy;
import com.lanyou.esb.redis.vo.HttpVo;
import com.lanyou.esb.redis.vo.IfAlarmVo;
import com.lanyou.esb.repository.HttpRepository;
import com.lanyou.esb.repository.IfAlarmHisRepository;
import com.lanyou.esb.repository.IfAlarmRepository;
import com.lanyou.esb.repository.IfAlarmWorkOrderHisRepository;
import com.lanyou.esb.repository.IfAlarmWorkOrderRepository;
import com.lanyou.esb.repository.IfAvgResTimesRepository;
import com.lanyou.esb.repository.QuantityControlRepository;
import com.lanyou.esb.vo.IfAvgResTimesVo;
import com.lanyou.esb.web.param.ServiceAlarmManagementParam;

/**
 * 流量告警管理服务类
 * 
 * @author Davey.wu
 */
@Service
public class ServiceAlarmManagementService {

	@Autowired
	QuantityControlRepository quantityControlRepository;

	@Autowired
	private IfAlarmHisRepository ifAlarmHisRepository;

	@Autowired
	private IfAlarmRepository ifAlarmRepository;

	@Autowired
	private IfAlarmWorkOrderRepository ifAlarmWorkOrderRepository;

	@Autowired
	private IfAlarmWorkOrderHisRepository ifAlarmWorkOrderHisRepository;

	@Autowired
	private HttpRepository httpRepository;

	@Autowired
	ParamSettingService paramSettingService;

	@Autowired
	private IfAvgResTimesRepository ifAvgResTimesRepository;

	@Autowired
	private UserRepository userRepository;

	@Autowired
	private HttpJedisProxy httpJedisProxy;

	@Autowired
	private UserLogService userLogService;

	private static FastDateFormat FASTDATEFORMAT_YYYYMMDDHHMMSS = FastDateFormat
			.getInstance(Constants.DATETIME_PATTERN_1);

	/**
	 * 查找告警管理信息
	 * 
	 * @param userId
	 *            ：用户标识
	 * @param param
	 *            ：查询条件
	 * @param pageable
	 *            ：分页
	 * @return
	 * @throws JsonParseException
	 * @throws JsonMappingException
	 * @throws IOException
	 */
	public Page<IfAlarmVo> findServiceAlarmManagementInfo(String userId,
			ServiceAlarmManagementParam param, Pageable pageable)
			throws JsonParseException, JsonMappingException, IOException {
		long firstIndex = pageable.getPageNumber() * pageable.getPageSize();
		int pageSize = pageable.getPageSize();
		List<IfAlarmVo> result = new ArrayList<>(pageSize);
		String startDate = param.getStartDateTime();
		String endDate = param.getEndDateTime();
		// 选择7天内，重设时间区间为7天前0点~昨天23点59分59秒
		if (param.isSevenBeforeDate()) {
			Date now = new Date();
			Calendar end = Calendar.getInstance();
			Calendar start = Calendar.getInstance();
			// 设置开始时间为7天前的0点
			start.setTime(now);
			start.add(Calendar.DAY_OF_MONTH, -7);
			start.set(Calendar.HOUR_OF_DAY, 0);
			start.set(Calendar.MINUTE, 0);
			start.set(Calendar.SECOND, 0);
			// 设置结束时间为昨天的23点59分59秒
			end.setTime(now);
			end.add(Calendar.DAY_OF_MONTH, -1);
			end.set(Calendar.HOUR_OF_DAY, 23);
			end.set(Calendar.MINUTE, 59);
			end.set(Calendar.SECOND, 59);

			startDate = FASTDATEFORMAT_YYYYMMDDHHMMSS.format(start);
			endDate = FASTDATEFORMAT_YYYYMMDDHHMMSS.format(end);
		} else if (param.isToday()) {
			// 选择今天，重设时间段为今天0点~当前时刻
			Date now = new Date();
			Calendar todayE = Calendar.getInstance();
			Calendar todayS = Calendar.getInstance();

			todayS.setTime(now);
			todayS.set(Calendar.HOUR_OF_DAY, 0);
			todayS.set(Calendar.MINUTE, 0);
			todayS.set(Calendar.SECOND, 0);

			todayE.setTime(now);

			startDate = FASTDATEFORMAT_YYYYMMDDHHMMSS.format(todayS);
			endDate = FASTDATEFORMAT_YYYYMMDDHHMMSS.format(todayE);
		}
		// 查看总记录数
		List<Object> totals = quantityControlRepository
				.findQuantityAlarmManagementTotalNum(userId,
						param.getFieldId(), param.getSystemId(), startDate,
						endDate, param.getIsolation(), param.getAlarmType());
		BigInteger total = null;
		if (totals != null && totals.size() > 0) {
			total = (BigInteger) totals.get(0);
		}
		// 没有记录返回空集
		if (total == null || total.longValue() <= 0) {
			return new PageImpl<IfAlarmVo>(new ArrayList<>(0), pageable, 0);
		}
		// 查询数据
		List<Object[]> objects = quantityControlRepository
				.findQuantityAlarmManagementInfo(userId, param.getFieldId(),
						param.getSystemId(), startDate, endDate,
						param.getIsolation(), param.getAlarmType(), firstIndex,
						pageSize - result.size());
		// 转换数据
		for (Object[] object : objects) {
			IfAlarmVo vo = new IfAlarmVo();
			vo.setId(object[0] != null ? (String) object[0] : "");
			vo.setIfId(object[1] != null ? (String) object[1] : "");
			vo.setIfType(object[2] != null ? (String) object[2] : "");
			vo.setIfName(object[3] != null ? (String) object[3] : "");
			vo.setIsIsolation(object[4] != null ? (String) object[4] : "");
			vo.setSystemId(object[5] != null ? (String) object[5] : "");
			vo.setSystemCode(object[6] != null ? (String) object[6] : "");
			vo.setSystemName(object[7] != null ? (String) object[7] : "");
			vo.setFieldId(object[8] != null ? (String) object[8] : "");
			vo.setFieldName(object[9] != null ? (String) object[9] : "");
			vo.setInEsbDate(object[10] != null ? (Date) object[10] : null);
			vo.setAlarmLevel(object[11] != null ? (String) object[11] : "");
			vo.setAlarmType(object[12] != null ? (String) object[12] : "");
			vo.setErrorReceiver(object[13] != null ? (String) object[13] : "");
			vo.setResCode(object[14] != null ? (String) object[14] : "");
			vo.setReqIp(object[15] != null ? (String) object[15] : "");
			vo.setReqMethod(object[16] != null ? (String) object[16] : "");
			vo.setReqUrl(object[17] != null ? (String) object[17] : "");
			vo.setReqMess(object[18] != null ? (String) object[18] : "");
			vo.setPeakValue(object[19] != null ? ((BigDecimal) object[19])
					.floatValue() : 0.0f);
			vo.setAnswerTime(object[20] != null ? ((BigDecimal) object[20])
					.floatValue() : 0.0f);
			vo.setAssignWorkCode(object[21] != null ? (String) object[21] : "");
			vo.setAssignDate(object[22] != null ? (Date) object[22] : null);
			vo.setFlow(object[23] != null ? ((Integer) object[23]).intValue()
					: 0);
			vo.setFlowThreshold(object[24] != null ? ((Integer) object[24])
					.intValue() : 0);
			vo.setErrorDate(object[25] != null ? (Date) object[25] : null);
			result.add(vo);
		}
		return new PageImpl<IfAlarmVo>(result, pageable, total.longValue());
	}

	/**
	 * 保存工单
	 * 
	 * @param ifAlarmId
	 *            ：告警信息标识
	 * @param errorAnalysis
	 *            ：分析结果
	 * @param date
	 *            ：處理日期
	 * @param user
	 *            ：處理用户
	 */
	public void saveWorkOrder(String ifAlarmId, String errorAnalysis,
			Date date, User user) throws IfAlarmException {
		IfAlarm ifAlarm = ifAlarmRepository.findOne(IfAlarm
				.idSpecification(ifAlarmId));
		if (ifAlarm == null) {
			throw new IfAlarmException("工单已被处理或不存在！", 0);
		}
		// 生成工单号
		IfAlarmWorkOrder workOrder = ifAlarmWorkOrderRepository
				.findByCode(ifAlarm.getAssignWorkCode());
		if (workOrder == null) {
			throw new IfAlarmException("找不到标识符为（" + ifAlarmId + "）告警记录相应的工单！",
					0);
		}
		// 保存工单
		saveWorkOrder(ifAlarm, workOrder, errorAnalysis, date, user);

		User receiver = null;
		if (StringUtils.isNotBlank(workOrder.getEmailReceiver())) {
			receiver = userRepository.findByUserCode(workOrder
					.getEmailReceiver());
		}
		if (receiver == null) {
			throw new IfAlarmException("工单保存成功，但找不到邮件接收者", 400);
		}
		// 发送邮件
		sendEmail(receiver, ifAlarm);
		// 紧急告警，发送短信
		if (AlarmLevel.URGENT.ValueCode.equals(ifAlarm.getAlarmLevel())) {
			try {
				sendMsg(receiver, ifAlarm);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * 发送短信
	 * 
	 * @param receiver
	 *            ：接收人
	 * @param ifAlarm
	 *            ：告警信息
	 * @throws IOException
	 * @throws HttpException
	 */
	private void sendMsg(User receiver, IfAlarm ifAlarm) throws HttpException,
			IOException {
		// HttpClient client = new HttpClient();
		// PostMethod post = new PostMethod("http://gbk.sms.webchinese.cn");
		// post.addRequestHeader("Content-Type",
		// "application/x-www-form-urlencoded;charset=gbk");// 在头文件中设置转码
		// NameValuePair[] data = { new NameValuePair("Uid", "本站用户名"),
		// new NameValuePair("Key", "接口安全密码"),
		// new NameValuePair("smsMob", "13725359466"),
		// new NameValuePair("smsText", "短信内容") };
		// post.setRequestBody(data);
		//
		// client.executeMethod(post);
		// Header[] headers = post.getResponseHeaders();
		// int statusCode = post.getStatusCode();
		// System.out.println("statusCode:" + statusCode);
		// for (Header h : headers) {
		// System.out.println(h.toString());
		// }
		// String result = new String(post.getResponseBodyAsString().getBytes(
		// "gbk"));
		// System.out.println(result);
		//
		// post.releaseConnection();
	}

	/**
	 * 隔离
	 * 
	 * @param ifAlarmId
	 *            ：告警信息标识
	 * @param user
	 *            :用户
	 * @throws Exception
	 */
	@Transactional
	public void isolation(String ifAlarmId, User user) throws Exception {
		IfAlarm ifAlarm = ifAlarmRepository.findOne(IfAlarm
				.idSpecification(ifAlarmId));
		if (ifAlarm == null) {
			throw new IfAlarmException("找不到标识符为（" + ifAlarmId + "）的告警记录！", 0);
		}
		Http http = httpRepository.findOne(Http.idSpecification(ifAlarm
				.getIfId()));
		if (http == null) {
			throw new IfAlarmException("找不到标识符为（" + ifAlarmId
					+ "）的告警记录所关联的接口信息！", 0);
		}
		// 接口已处于隔离状态，结束流程
		if (IsolationStatus.ISOLATION.ValueCode.equals(http.getIfOlation())) {
			throw new IfAlarmException("接口已处于隔离状态！", 0);
		}
		http.setIfOlation(IsolationStatus.ISOLATION.ValueCode);
		httpRepository.save(Arrays.asList(http));
		// 更新REDIS相应接口的数据
		updateHttpRedisData(http);

		userLogService.save(UserLogOpt.MaintenanceServiceAlarm, null,
				String.format("隔离接口“%s”", http.getName()));
	}

	/**
	 * 取消接口隔离
	 * 
	 * @param ifAlarmId
	 *            ：告警信息标识
	 * @param user
	 *            :用户
	 * @throws Exception
	 */
	@Transactional
	public void cancelIsolation(String ifAlarmId, User user) throws Exception {
		IfAlarm ifAlarm = ifAlarmRepository.findOne(IfAlarm
				.idSpecification(ifAlarmId));
		if (ifAlarm == null) {
			throw new IfAlarmException("找不到标识符为（" + ifAlarmId + "）的告警记录！", 0);
		}
		Http http = httpRepository.findOne(Http.idSpecification(ifAlarm
				.getIfId()));
		if (http == null) {
			throw new IfAlarmException("找不到标识符为（" + ifAlarmId
					+ "）的告警记录所关联的接口信息！", 0);
		}
		// 接口已处于未隔离状态，结束流程
		if (IsolationStatus.NOT_ISOLATION.ValueCode.equals(http.getIfOlation())) {
			throw new IfAlarmException("接口已处于未隔离状态！", 0);
		}
		http.setIfOlation(IsolationStatus.NOT_ISOLATION.ValueCode);
		httpRepository.save(Arrays.asList(http));

		// 更新REDIS相应接口的数据
		updateHttpRedisData(http);
		userLogService.save(UserLogOpt.MaintenanceServiceAlarm, null,
				String.format("取消接口“%s”隔离", http.getName()));
	}

	/**
	 * 获取接口平均响应时间
	 * 
	 * @param ifId
	 *            ：接口标识
	 * @param occDate
	 *            ：告警时间点
	 * @return
	 * @throws IfAlarmException
	 */
	public List<IfAvgResTimesVo> findIfAvgResTiems(String ifId, Date occDate)
			throws IfAlarmException {
		if (occDate == null) {
			throw new IfAlarmException("告警时间不能为空", 0);
		}
		Date startDate = DateUtils.addHours(occDate,
				-CommonUtils.ALARM_AVG_TIME_SECTION);
		Date endDate = DateUtils.addHours(occDate,
				CommonUtils.ALARM_AVG_TIME_SECTION);
		List<Object[]> objects = ifAvgResTimesRepository.findByIfIdAndDate(
				ifId, startDate, endDate);
		if (objects == null || objects.isEmpty()) {
			return null;
		}
		List<IfAvgResTimesVo> result = new ArrayList<>(objects.size());
		for (Object[] object : objects) {
			IfAvgResTimesVo vo = new IfAvgResTimesVo();
			vo.setIfId(object[0] == null ? "" : (String) object[0]);
			vo.setAvgResTimes(object[1] == null ? 0.0f
					: ((BigDecimal) object[1]).floatValue());
			vo.setStartDate(object[2] == null ? null
					: FASTDATEFORMAT_YYYYMMDDHHMMSS.format((Date) object[2]));
			result.add(vo);
		}
		return result;
	}

	/**
	 * 保存工单
	 * 
	 * @param ifAlarm
	 * @param workOrder
	 * @param errorAnalysis
	 * @param date
	 * @param user
	 * @throws IfAlarmException
	 */
	@Transactional
	private void saveWorkOrder(IfAlarm ifAlarm, IfAlarmWorkOrder workOrder,
			String errorAnalysis, Date date, User user) throws IfAlarmException {
		// 去除重复消息
		errorAnalysis = filterDulpMsg(errorAnalysis, ",");
		// 生成告警历史
		IfAlarmHis ifAlarmHis = new IfAlarmHis();
		ifAlarmHis.setId(ifAlarm.getId());
		ifAlarmHis.setIfId(ifAlarm.getIfId());
		ifAlarmHis.setIfType(ifAlarm.getIfType());
		ifAlarmHis.setIfName(ifAlarm.getIfName());
		FieldSystem fieldSystem = new FieldSystem();
		fieldSystem.setId(ifAlarm.getFieldId());
		ifAlarmHis.setFieldSystem(fieldSystem);
		ifAlarmHis.setSystemCode(ifAlarm.getSystemCode());
		ifAlarmHis.setAlarmType(ifAlarm.getAlarmType());
		ifAlarmHis.setAlarmLevel(ifAlarm.getAlarmLevel());
		ifAlarmHis.setInEsbTime(ifAlarm.getInEsbTime());
		ifAlarmHis.setOutEsbTime(ifAlarm.getOutEsbTime());
		ifAlarmHis.setPlatReqDate(ifAlarm.getPlatReqDate());
		ifAlarmHis.setPlatResDate(ifAlarm.getPlatResDate());
		ifAlarmHis.setFlow(ifAlarm.getFlow());
		ifAlarmHis.setAnswerTime(ifAlarm.getAnswerTime());
		ifAlarmHis.setReqThreshold(ifAlarm.getReqThreshold());
		ifAlarmHis.setErrorDate(ifAlarm.getErrorDate());
		ifAlarmHis.setErrorReceiver(ifAlarm.getErrorReceiver());
		ifAlarmHis.setAssignWorkCode(ifAlarm.getAssignWorkCode());
		ifAlarmHis.setIsEnable(ifAlarm.getIsEnable());
		ifAlarmHis.setCreator(ifAlarm.getCreator());
		ifAlarmHis.setCreateTime(ifAlarm.getCreateTime());
		ifAlarmHis.setModifier(ifAlarm.getModifier());
		ifAlarmHis.setModifyTime(ifAlarm.getModifyTime());

		ifAlarmHis.setResCode(ifAlarm.getResCode());
		ifAlarmHis.setReqIp(ifAlarm.getReqIp());
		ifAlarmHis.setReqMethod(ifAlarm.getReqMethod());
		ifAlarmHis.setReqUrl(ifAlarm.getReqUrl());
		ifAlarmHis.setReqMess(ifAlarm.getReqMess());
		ifAlarmHis.setPeakValue(ifAlarm.getPeakValue());
		ifAlarmHis.setRepeat(ifAlarm.getRepeat());

		// 生成工单历史
		IfAlarmWorkOrderHis workOrderHis = new IfAlarmWorkOrderHis();
		workOrderHis.setId(workOrder.getId());
		workOrderHis.setCode(workOrder.getCode());
		workOrderHis.setAssignDate(workOrder.getAssignDate());
		workOrderHis.setIfId(workOrder.getIfId());
		workOrderHis.setAnalysis(errorAnalysis);
		workOrderHis.setDealDate(new Date());
		workOrderHis.setDealPerson(user.getUserCode());
		workOrderHis.setEmailReceiver(workOrder.getEmailReceiver());
		workOrderHis.setIsEnable(workOrder.getIsEnable());
		workOrderHis.setCreator(workOrder.getCreator());
		workOrderHis.setCreateDate(workOrder.getCreateDate());
		workOrderHis.setModifier(workOrder.getModifier());
		workOrderHis.setLastUpDate(workOrder.getLastUpDate());

		// 保存告警历史
		ifAlarmHisRepository.save(Arrays.asList(ifAlarmHis));
		// 删除告警信息
		ifAlarmRepository.delete(Arrays.asList(ifAlarm));
		// 保存告警工单历史
		ifAlarmWorkOrderHisRepository.save(Arrays.asList(workOrderHis));
		// 删除告警工单 信息
		ifAlarmWorkOrderRepository.delete(Arrays.asList(workOrder));

		userLogService.save(UserLogOpt.MaintenanceServiceAlarm, null,
				String.format("保存工单“%s”", workOrder.getCode()));
	}

	/**
	 * 去除重复消息
	 * 
	 * @param msg
	 * @return
	 */
	private String filterDulpMsg(String msg, String seprator) {
		if (StringUtils.isBlank(msg) || msg.indexOf(seprator) < 0) {
			return msg;
		}
		String[] arr = msg.split(seprator);
		Map<String, Boolean> map = new HashMap<>(arr.length);
		StringBuilder builder = new StringBuilder();
		int i = 0;
		for (String s : arr) {
			if (map.get(s) != null) {
				continue;
			}
			map.put(s, true);
			if (i == 0) {
				builder.append(s);
			} else {
				builder.append(",").append(s);
			}
			i++;
		}
		return builder.toString();
	}

	/**
	 * 发送邮件
	 * 
	 * @param user
	 *            ：接收者
	 * @param ifAlarm
	 *            ：告警信息
	 * @throws IfAlarmException
	 */
	private void sendEmail(User user, IfAlarm ifAlarm) throws IfAlarmException {
		String templateName = "IfAlarmEmailTemplate";
		String subjectName = "接口异常修复通知！";
		Map<String, Object> map = new HashMap<>();
		map.put("emailAddress", user.getEmailAddress());
		map.put("userCode", user.getUserCode());
		map.put("ifName", ifAlarm.getIfName());
		try {
			sendEmail(map, templateName, subjectName);
		} catch (Exception e) {
			throw new IfAlarmException("发送邮件失败:" + e.getMessage(), 0);
		}
	}

	/**
	 * 发送邮件
	 * 
	 * @param data
	 * @param templateName
	 * @param subjectName
	 */
	public void sendEmail(Map data, String templateName, String subjectName) {
		VelocityEngine velocityEngine = (VelocityEngine) MailUtil.EmailEngine()
				.get("velocityEngine");
		JsonObject smtpService = (JsonObject) MailUtil.EmailEngine().get(
				"smtpService");
		MimeMessagePreparator preparator = new MimeMessagePreparator() {
			@Override
			public void prepare(MimeMessage mimeMessage) throws Exception {
				MimeMessageHelper message = new MimeMessageHelper(mimeMessage,
						true, "utf-8");
				message.setSubject(subjectName);
				message.setTo((String) data.get("emailAddress"));
				message.setFrom(GsonUtil.getString(smtpService, "emailAddress",
						"")); // could be parameterized...
				String text = VelocityEngineUtils.mergeTemplateIntoString(
						velocityEngine, templateName + ".vm", "utf-8", data);
				message.setText(text, true);
			}
		};
		JavaMailSenderImpl javaMailSenderImpl = (JavaMailSenderImpl) MailUtil
				.EmailEngine().get("javaMailSenderImpl");
		javaMailSenderImpl.send(preparator);
	}

	/**
	 * 修改Redis中对应数据类
	 * 
	 * @param http
	 * @return
	 * @throws Exception
	 */
	private boolean updateHttpRedisData(Http http) throws Exception {
		/* HttpJedisProxy httpJedisProxy = new HttpJedisProxy(); */
		try {
			HttpVo target = HttpVo.getInstance(http);
			httpJedisProxy.hset(httpJedisProxy.generateKeyFromObject(target),
					target);
		} catch (JsonProcessingException e) {
			throw new ServiceHandlerException(
					CommonUtils.MSG_JSON_PARSING_ERROR,
					CommonUtils.CODE_JSON_PARSING_ERROR);
		} catch (JedisException e) {
			throw new ServiceHandlerException(
					CommonUtils.MSG_CONNECT_REDIS_FAIED,
					CommonUtils.CODE_CONNECT_REDIS_FAIED);
		} catch (Exception e) {
			throw new ServiceHandlerException(
					CommonUtils.MSG_UPDATE_REDIS_DATA_FAIED,
					CommonUtils.CODE_UPDATE_REDIS_DATA_FAIED);

		}
		return true;
	}

}
